wastedstudiofandomcom-20200214-history
Programming Standards
Files and Directories The name of our directories and files starts with an upper case letter. Each word starts with an upper case letter. Our sources and headers directories will be named Sources '''and '''Headers. Sources/BaseClass.cpp Headers/BaseClass.h SuperLongDirectory/SuperCoolFile.cpp Naming standards A class name always starts with an''' '''upper case letter. All variables names start with a lower case and methods start with an upper case letter. If the class is an interface, the class name starts with an upper "i", and if it is an abstract class, its name starts with an upper "a". Class INameInterface Class ANameAbstract Again, if the name is made of several words, each of them, except the first one which follows the previous rule, starts with an upper case letter. If a method contains one or several variables, they all start with a backquote and a lower case letter after it. class MyClass {' '''private: ' : 'Type variableName; ' : 'auto MethodName(_paramName, _otherParamName) -> Type; ' 'public: ' : 'Type* var; ' '''} No "s" at the end of the name of any method/class/variable but you can add words to describe it (ex: entityList). Few exceptions exist for methods name (ex : GetComponents) but have to be approve (GetComponent already exist, it's logic and simple and is like Unity). Coding rules Private elements are shown at the top of the class, then protected and finally public elements. Our methods follow this schema auto FunctionName(type variableName) -> ReturnType { code; } /!\ /!\ /!\ THIS SCHEMA DOESN'T WORK FOR SLOTS METHODS /!\ /!\ /!\ Getters and setters have their own definition on the same line. Both of them are separated from each other. A setter method has to include at least a verification of the value. Class: ' '{ ' '''private: ' 'protected: ' 'public: ' : '''inline auto GetVar1 -> Type {return var1;} : inline auto GetVar2 -> Type {return var2;} ''' : '''inline auto SetVar1(int _var1) -> void {if (_var1 > 100) _var1 = 100; var1 = _var1;} public slots: Type Function(); } ''' Each function or method contains 25 lines maximum. If a method is only one line length it is define in the .h with the '''inline key. The keyword "this" is a pointer, we only use it if we have to make a difference between two variables. If a method function/method contains too many parameters, creating a new class to contain it is a solution. After that you can have a default constructor and individuals setters. AddPerson(string name, int age, int phone, Color3f skin, Color3f hair, Color4f eyes, float size, int gender) AddPerson(Identity id, Visual v); Identity id("Georges", 12, 123456, 1.82, 1); Visual v(Color3f(1.0f, 1.0f, 1.0f), Color3f(0.0f, 0.0f, 0.0f), Color3f(0.0f, 0.0f, 1.0f)); Person P = AddPerson(id, v); Person george = AddPerson(P); ' '''george.SetName("Albert"); ' '''george.SetAge(21); Coding techniques The inline keyword has to be used. There are several reasons to use it but there are specific rules to use it. First, an inline function is a little or/and an often used function. A function defined with the "#define" keyword can be replaced by the "inline" keyword. If there are too many inline functions, they can lower the process due to too many access to the virtual memory. An inline function is compressed, the function will be used and executed faster but the .exe size will be bigger, so you have to be careful with it without being too shy to use it.